home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2001 / MacHack 2001.toast / pc / The Hacks / asciishopsource / asciiShop / mainFrame.java.back < prev    next >
Encoding:
Text File  |  2001-06-23  |  10.1 KB  |  341 lines

  1. /** 
  2.  * mainFrame.java
  3.  *
  4.  * Title:            ASCII Shop
  5.  * Description:        The goal of this program is to provide many functionalities of photoshop, with ASCII art.
  6.  * @author            Expotech
  7.  * @version            
  8.  */
  9.  
  10. package asciiShop;
  11.  
  12. import java.awt.*;
  13. import java.awt.event.*;
  14. import java.io.*;
  15.  
  16. public class mainFrame extends java.awt.Frame {
  17.  
  18. char[][] artBuffer2;
  19. int useLength, length1, length2;
  20. int globalCount = 0;
  21. PrintWriter writeToFile;
  22. String bigString;
  23. int i, j, k;
  24. int countForOpenFile, countForOpenFileSave;
  25. FileDialog newFile;
  26. String pathToFile;
  27. String file;
  28. BufferedReader openFile;
  29. String[] artBuffer; 
  30. String[][] layerBuffer;
  31.  
  32.  
  33. // IMPORTANT: Source code between BEGIN/END comment pair will be regenerated
  34. // every time the form is saved. All manual changes will be overwritten.
  35. // BEGIN GENERATED CODE
  36.     // member declarations
  37.     java.awt.TextArea fileBuffer = new java.awt.TextArea();
  38.     java.awt.List layers = new java.awt.List();
  39.     java.awt.MenuBar menuBar1 = new java.awt.MenuBar();
  40.     java.awt.Menu menuFile = new java.awt.Menu();
  41.     java.awt.MenuItem menuFileOpen = new java.awt.MenuItem();
  42.     java.awt.MenuItem menuFileWriteOut = new java.awt.MenuItem();
  43.     java.awt.MenuItem menuFileQuit = new java.awt.MenuItem();
  44.     java.awt.MenuItem menuFileRefreshArt = new java.awt.MenuItem();
  45.     java.awt.Menu menuLayers = new java.awt.Menu();
  46.     java.awt.MenuItem menuLayersAddLayer = new java.awt.MenuItem();
  47.     java.awt.MenuItem menuLayersRemoveLayer = new java.awt.MenuItem();
  48.     java.awt.MenuItem menuLayersRedrawLayers = new java.awt.MenuItem();
  49.     java.awt.Menu menumirror = new java.awt.Menu();
  50.     java.awt.MenuItem menumirrorSideWays = new java.awt.MenuItem();
  51.     java.awt.MenuItem menumirrorFlipVerticle = new java.awt.MenuItem();
  52. // END GENERATED CODE
  53.  
  54.     public mainFrame() {
  55.     }
  56.  
  57.     public void initComponents() throws Exception {
  58. // IMPORTANT: Source code between BEGIN/END comment pair will be regenerated
  59. // every time the form is saved. All manual changes will be overwritten.
  60. // BEGIN GENERATED CODE
  61.         // the following code sets the frame's initial state
  62.  
  63.         fileBuffer.setLocation(new java.awt.Point(60, 70));
  64.         fileBuffer.setVisible(true);
  65.         fileBuffer.setSize(new java.awt.Dimension(480, 360));
  66.  
  67.         layers.setLocation(new java.awt.Point(570, 270));
  68.         layers.setVisible(true);
  69.         layers.setSize(new java.awt.Dimension(130, 160));
  70.  
  71.         menuBar1.add(menuFile);
  72.         menuBar1.add(menuLayers);
  73.         menuBar1.add(menumirror);
  74.  
  75.         menuFile.setLabel("File");
  76.         menuFile.add(menuFileOpen);
  77.         menuFile.add(menuFileWriteOut);
  78.         menuFile.add(menuFileQuit);
  79.         menuFile.add(menuFileRefreshArt);
  80.  
  81.         menuFileOpen.setLabel("Open");
  82.  
  83.         menuFileWriteOut.setLabel("Write Out");
  84.  
  85.         menuFileQuit.setLabel("Quit");
  86.  
  87.         menuFileRefreshArt.setLabel("Refresh Art");
  88.  
  89.         menuLayers.setLabel("Layers");
  90.         menuLayers.add(menuLayersAddLayer);
  91.         menuLayers.add(menuLayersRemoveLayer);
  92.         menuLayers.add(menuLayersRedrawLayers);
  93.  
  94.         menuLayersAddLayer.setLabel("Add Layer");
  95.  
  96.         menuLayersRemoveLayer.setLabel("Remove Layer");
  97.  
  98.         menuLayersRedrawLayers.setLabel("Redraw Layers");
  99.  
  100.         menumirror.setLabel("mirror");
  101.         menumirror.add(menumirrorSideWays);
  102.         menumirror.add(menumirrorFlipVerticle);
  103.  
  104.         menumirrorSideWays.setLabel("invert");
  105.  
  106.         menumirrorFlipVerticle.setLabel("Flip Verticle");
  107.  
  108.         setLocation(new java.awt.Point(5, 40));
  109.         setTitle("asciiShop.mainFrame");
  110.         setLayout(null);
  111.         setMenuBar(menuBar1);
  112.         setSize(new java.awt.Dimension(736, 520));
  113.         add(fileBuffer);
  114.         add(layers);
  115.  
  116.  
  117.         fileBuffer.addTextListener(new java.awt.event.TextListener() {
  118.             public void textValueChanged(java.awt.event.TextEvent e) {
  119.                 fileBufferTextValueChanged(e);
  120.             }
  121.         });
  122.         layers.addItemListener(new java.awt.event.ItemListener() {
  123.             public void itemStateChanged(java.awt.event.ItemEvent e) {
  124.                 layersItemStateChanged(e);
  125.             }
  126.         });
  127.         menuFileOpen.addActionListener(new java.awt.event.ActionListener() {
  128.             public void actionPerformed(java.awt.event.ActionEvent e) {
  129.                 menuFileOpenActionPerformed(e);
  130.             }
  131.         });
  132.         menuFileWriteOut.addActionListener(new java.awt.event.ActionListener() {
  133.             public void actionPerformed(java.awt.event.ActionEvent e) {
  134.                 menuFileWriteOutActionPerformed(e);
  135.             }
  136.         });
  137.         menuFileRefreshArt.addActionListener(new java.awt.event.ActionListener() {
  138.             public void actionPerformed(java.awt.event.ActionEvent e) {
  139.                 menuFileRefreshArtActionPerformed(e);
  140.             }
  141.         });
  142.         menuLayersAddLayer.addActionListener(new java.awt.event.ActionListener() {
  143.             public void actionPerformed(java.awt.event.ActionEvent e) {
  144.                 menuLayersAddLayerActionPerformed(e);
  145.             }
  146.         });
  147.         menumirrorSideWays.addActionListener(new java.awt.event.ActionListener() {
  148.             public void actionPerformed(java.awt.event.ActionEvent e) {
  149.                 menumirrorSideWaysActionPerformed(e);
  150.             }
  151.         });
  152.         addWindowListener(new java.awt.event.WindowAdapter() {
  153.             public void windowClosing(java.awt.event.WindowEvent e) {
  154.                 thisWindowClosing(e);
  155.             }
  156.         });
  157.  
  158. // END GENERATED CODE
  159.     }
  160.   
  161.       private boolean mShown = false;
  162.       
  163.     public void addNotify() {
  164.         super.addNotify();
  165.         
  166.         if (mShown)
  167.             return;
  168.             
  169.         // move components to account for insets
  170.         Insets insets = getInsets();
  171.         Component[] components = getComponents();
  172.         for (int i = 0; i < components.length; i++) {
  173.             Point location = components[i].getLocation();
  174.             location.move(location.x, location.y + insets.top);
  175.             components[i].setLocation(location);
  176.         }
  177.  
  178.         mShown = true;
  179.     }
  180.  
  181.     // Close the window when the close box is clicked
  182.     void thisWindowClosing(java.awt.event.WindowEvent e) {
  183.         setVisible(false);
  184.         dispose();
  185.         System.exit(0);
  186.     }
  187.     
  188.     public void list1ItemStateChanged(java.awt.event.ItemEvent e) {
  189.     }
  190.     
  191.     public void layersItemStateChanged(java.awt.event.ItemEvent e) {
  192.     }
  193.     
  194.     public void fileBufferTextValueChanged(java.awt.event.TextEvent e) {
  195.     }
  196.     
  197.     public void menuFileOpenActionPerformed(java.awt.event.ActionEvent e) {
  198.         bigString = new String("");
  199.         countForOpenFile = 0; // To get the number of lines to use with artBuffer
  200.         newFile = new FileDialog(this, "Open File", FileDialog.LOAD); // Opens and open file dialog box
  201.         newFile.setVisible(true);
  202.         pathToFile = newFile.getDirectory();
  203.         file = newFile.getFile();
  204.         artBuffer = new String[200];
  205.         try {
  206.             System.out.println(pathToFile + file);
  207.             openFile = new BufferedReader(new FileReader(pathToFile + file));
  208.         } catch(FileNotFoundException badStuff) {
  209.             System.out.println("The file could not be found... DAMN MICROSOFT!!!");
  210.         }
  211.             try {
  212.                 while( (artBuffer[countForOpenFile] = openFile.readLine()).equals("***end***") == false)
  213.                 {
  214.                         countForOpenFile++;
  215.                 }
  216.             } catch(IOException badStuff) {
  217.                 System.out.println("HOW THE HELL DiD YOU GET THIS ERROR!?");
  218.             }
  219.         System.out.println("How many lines in the art: " + countForOpenFile);
  220.         for(i = 0; i < countForOpenFile; i++) {
  221.             bigString = bigString + artBuffer[i] + "\n";
  222.         }
  223.         fileBuffer.setText(bigString);
  224.         countForOpenFileSave = countForOpenFile;
  225.     }
  226.     
  227.     public void menuFileWriteOutActionPerformed(java.awt.event.ActionEvent e) {
  228.         newFile = new FileDialog(this, "Save File", FileDialog.SAVE);
  229.         newFile.setVisible(true);
  230.         pathToFile = newFile.getDirectory();
  231.         file = newFile.getFile();
  232.         try {
  233.         writeToFile = new PrintWriter(new FileWriter(pathToFile + file), true);
  234.         System.out.println("Wrote to file: " + pathToFile + file);
  235.         } catch(IOException badStuff) {
  236.             System.out.println("GODDAMN HOW THE HELL DID YOU MANAGE TO GET THIS ERROR!?");
  237.         }
  238.         bigString = fileBuffer.getText();
  239.         writeToFile.println(bigString + "\n***end***");
  240.         System.out.println("Wrote out to file: " + pathToFile + file + "\n" + bigString + "***end***");
  241.         return;
  242.     }
  243.     
  244.     public void menuLayersAddLayerActionPerformed(java.awt.event.ActionEvent e) {
  245.         {
  246.             String [][] temp;
  247.             
  248.             temp = layerBuffer;
  249.             layerBuffer = new String[globalCount+1][200];
  250.             for(int i=0; i < globalCount; i++)
  251.                 layerBuffer[i] = temp[i];
  252.         }
  253.         countForOpenFile = 0; // To get the number of lines to use with artBuffer
  254.         newFile = new FileDialog(this, "Add Layer", FileDialog.LOAD); // Opens and open file dialog box
  255.         newFile.setVisible(true);
  256.         pathToFile = newFile.getDirectory();
  257.         file = newFile.getFile();
  258.         layerBuffer[globalCount] = new String[200];
  259.             System.out.println("Trying to apply layer: " + pathToFile + file);
  260.             try {
  261.                 openFile = new BufferedReader(new FileReader(pathToFile + file));
  262.             } catch(IOException badStuff) {
  263.                 System.out.println("HOW THE HELL DID YOU GET THIS ERROR!? - 3");
  264.             }
  265.             try {
  266.                 while( (layerBuffer[globalCount][countForOpenFile] = openFile.readLine()).equals("***end***") == false)
  267.                 {
  268.                         countForOpenFile++;
  269.                 }
  270.             } catch(IOException badStuff) {
  271.                 System.out.println("HOW THE HELL DID YOU GET THIS ERROR!? -2");
  272.             }
  273.             length1 = artBuffer[0].length();
  274.             length2 = layerBuffer[globalCount][0].length();
  275.             if(length1 < length2) {
  276.                 useLength = length2;
  277.             }
  278.             else {
  279.                 useLength = length1;
  280.             }
  281.             
  282.             artBuffer2 = new char[200][200];
  283.             
  284.             for(i = 0; i < countForOpenFileSave; i++) {
  285.                 for(k = 0; k < useLength; k++) {
  286.                     artBuffer2[i][k] = artBuffer[i].charAt(k);
  287.                 }
  288.                 for(j = 0; j < useLength; j++) {
  289.                     if(layerBuffer[i][j].charAt(j) != ' ') {
  290.                         artBuffer2[i][j] = layerBuffer[i][j].charAt(j);
  291.                     }
  292.                     else {
  293.                         artBuffer2[i][j] = ' ';
  294.                     }
  295.                 }    
  296.             }
  297.             for(i = 0; i < countForOpenFileSave; i++) {
  298.                 for(k = 0; k < useLength; k++) {
  299.                     System.out.println(artBuffer2[i][k]);
  300.                 }
  301.             }
  302.             for(i = 0; i < countForOpenFileSave; i++) {
  303.                 System.out.println(artBuffer[i]);
  304.             }
  305.             globalCount++;
  306.     }
  307.     
  308.     public void menumirrorSideWaysActionPerformed(java.awt.event.ActionEvent e) {
  309.         asciiLibs foo = new asciiLibs(artBuffer);
  310.         foo.invert(countForOpenFile);
  311.         refresh();
  312.     }
  313.     
  314.     public void menuFileRefreshArtActionPerformed(java.awt.event.ActionEvent e) {
  315.         bigString = "";
  316.         //fileBuffer.setText("");
  317.         for(i = 0; i < countForOpenFile; i++) {
  318.             bigString = bigString + artBuffer[i] + "\n";
  319.         }
  320.         fileBuffer.setText(bigString);
  321.         //fileBuffer.replaceText(bigString, 0, 40000);
  322.     }
  323.     public void refresh() {
  324.         bigString = "";
  325.         for(i = 0; i < countForOpenFile; i++) {
  326.             bigString = bigString + artBuffer[i] + "\n";
  327.         }
  328.         fileBuffer.setText(bigString);
  329.     }
  330.     
  331.     public void menumirrorFlipVerticleActionPerformed(java.awt.event.ActionEvent e) {
  332.     }
  333.     
  334.     
  335.     
  336.     
  337.     /*layerBuffer = new String[globalCount][];
  338.     layerBuffer[2] = new String[2]{"blah","soo"};
  339.     system.out.println(layerBuffer[2][1])*/
  340. }
  341.